/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kurs;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.*;


/**
 *
 * @author user
 */
abstract class Pet {
    String name;
    int age;
    boolean hungry;
    abstract void voice();
    void food() {
        hungry = false;
    }
}
class Snake extends Pet {
    double length;
    void voice() {
        //System.out.println("Шшш-ш-ш");
        //return 1;
    }
}
class Dog extends Pet {
    void voice() {
        System.out.println("Гав-гав");
        //return 2;
    }
}
class PatrolDog extends Dog {
    void voice() {
        System.out.println("Ррр-р-р");
        //return 3;
    }
}
class Cat extends Pet {
    void voice() {
        //int age=2;
        //System.out.println(age);
        //return 1;
        
    }
}
class Fish extends Pet {
    void voice() {
        System.out.println("Тихо");
        //return 5;
    }
}




public class Main {
    public static void main(String[] args) throws IOException {

     //   Main wr_ar=new Main();
     //   wr_ar.wr_ar();


        Main wr_ar_1=new Main();
        wr_ar_1.re_ar();
/*
        ArrayList al=new ArrayList();

        al.add("1");
        al.add("2");
        Collections.sort(al,Collections.reverseOrder());
        System.out.println(al);

        FileOutputStream fileOut = new FileOutputStream("/home/user/UserDataFile.txt");
        ObjectOutputStream oos = new ObjectOutputStream (fileOut);
        oos.writeUnshared(al);*/




        // ошибка: Pet zorka = new Pet();
        //Cat nemo = new Cat();
        //nemo.voice();
    }
/*
    void wr_ar() throws FileNotFoundException, IOException {
                ArrayList al=new ArrayList();


        al.add("123");
        al.add("456");
        Collections.sort(al,Collections.reverseOrder());
        System.out.println(al);
        FileOutputStream fileOut = new FileOutputStream("/home/user/UserDataFile.txt");
        ObjectOutputStream oos = new ObjectOutputStream (fileOut);
        oos.writeObject(al);

}*/

    void re_ar() throws IOException{
       	        // Lets create an arrayList object full of String types.
	        ArrayList<String> arrayOfStrings = new ArrayList<String>();

	        try {
	            // Create our bufferedreader to read the file
	            BufferedReader reader = new BufferedReader(new FileReader("/home/user/BRANCH.txt"));

	            // Line to hold the line read from file
	            String line = "";

	            // Loop through the file reading in lines and storing in "line". Do this until readLine returns null (end of file)
	            // Add each line to our arraylist object
	            while ((line = reader.readLine()) != null) {
	                arrayOfStrings.add(line);
	            }
                    Collections.sort(arrayOfStrings);

	            // Now use a foreach style loop to read each string in our arraylist. Notice we don't have to cast
	            // to string because we told the arraylist that it will hold strings at the start.
	            for (String readline : arrayOfStrings) {
	                System.out.println(readline);
	            }

	            reader.close();
	        }
	        catch (Exception ex) { System.out.println("Exception: " + ex.getMessage()); }


    }

}

